#include<bits/stdc++.h>
using namespace std;
struct node{
    int d,v,a;
}car[100005];
int p[100005];
int Next[100005];
int n,m,L,V;
int Ans;
int ans;
bool ok(vector<int> E){
    int sum=0;
    if(E.size()==0) return 0;
    int O=1,P=1;
    for(int P=1; P<E.size(); P++){
        while(O<=n&&car[O].d<=E[P]){
            Next[O]=E[P];
            O++;
        }
    }
    for(;O<=n;O++){
        Next[O]=1e9;
    }
    for(int i=1; i<=n; i++){
            if(E[E.size()-1]<car[i].d) continue;
        if(car[i].a<0){
            if(car[i].v<=V) continue;
            int S=car[i].d+(int)(V*V-car[i].v*car[i].v)/(2*car[i].a);
            if(Next[i]<S){
                sum++;
            }
        }
        else if(car[i].a>0){
            if(car[i].v*car[i].v+2*car[i].a*(E[E.size()-1]-car[i].d)>V*V) sum++;
        }
        else{
            if(car[i].v>V) sum++;
        }
    }
    return sum==ans;
}
void dfs(int dep,vector<int> E){
    if(dep>m){
        if(ok(E)){
            Ans=max(Ans,m-(int)E.size()+1);
        }
        return;
    }
    dfs(dep+1,E);
    E.push_back(p[dep]);
    dfs(dep+1,E);
}
bool cmp(node i, node j ){
    return i.d<j.d;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n; i++){
            cin>>car[i].d>>car[i].v>>car[i].a;
        }
        for(int i=1; i<=m; i++){
            cin>>p[i];
        }
        sort(car+1,car+n+1,cmp);
        int O=1,P=1;
        for(int P=1; P<=m; P++){
            while(O<=n&&car[O].d<=p[P]){
                Next[O]=p[P];
                O++;
            }
        }
        int flag=0;
        ans=0;
        for(int i=1; i<=n; i++){
            if(car[i].a<0){
                    flag=1;
                if(car[i].v<=V) continue;
                int S=car[i].d+(int)(V*V-car[i].v*car[i].v)/(2*car[i].a);
                if(Next[i]<S){
                    ans++;
                }
            }
            else if(car[i].a>0){
                if(car[i].v*car[i].v+2*car[i].a*(p[m]-car[i].d)>V*V) ans++;
            }
            else{
                if(car[i].v>V) ans++;
            }
        }
        cout<<ans<<" ";
        if(flag==0){
            cout<<n-1<<"\n";
            continue;
        }
        Ans=0;
        vector<int> now;
        now.push_back(0);
        dfs(1,now);
        cout<<Ans<<"\n";
    }
    return 0;
}
/*
1
5 5 15 3
0 3 0
12 4 0
1 1 4
5 5 -2
6 4 -4
2 5 8 9 15
*/
